//
//  BDDiscoverLeftTableViewCell.m
//  BadBoy
//
//  Created by wen on 16/12/15.
//  Copyright © 2016年 niusaibing. All rights reserved.
//

#import "BDDiscoverLeftTableViewCell.h"


@implementation BDDiscoverLeftTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addSubViews];
    }
    return self;
}

- (YYAnimatedImageView *)hongbaoImage {
    if (!_hongbaoImage) {
        static YYImage *image =  nil;
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            image = [YYImage imageNamed:@"hongbao_gif1.gif"];
        });
        
        self.hongbaoImage = [[YYAnimatedImageView alloc] initWithImage:image];
        [self.contentView addSubview:_hongbaoImage];
    }
    return _hongbaoImage;
}

-(UIImageView *)coverImage{
    if (!_coverImage) {
        _coverImage = [[UIImageView alloc]init];
        _coverImage.image = [UIImage imageNamed:@"KTV"];
        _coverImage.userInteractionEnabled = YES;
    }
    return _coverImage;
}
-(UILabel *)shopName{
    if (!_shopName) {
        _shopName = [[UILabel alloc]init];
        _shopName.textColor = KBDNameColor;
        _shopName.font = [UIFont systemFontOfSize:15];
        _shopName.userInteractionEnabled = YES;
    }
    return _shopName;
}

- (UILabel *)tuiguangLabel{
    if (!_tuiguangLabel) {
        self.tuiguangLabel = [[UILabel alloc] init];
        _tuiguangLabel.backgroundColor = [UIColor colorWithHexString:@"#ff8400"];
        _tuiguangLabel.font = [UIFont systemFontOfSize:14];
        _tuiguangLabel.size = CGSizeMake(15, 15);
        _tuiguangLabel.text = ASLocalizedString(@"推");
        _tuiguangLabel.textColor = [UIColor whiteColor];
        _tuiguangLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _tuiguangLabel;
}

- (YYStarView *)starView{
    if (!_starView) {
        self.starView = [[YYStarView alloc] init];
    }
    return _starView;
}
-(UILabel *)EvaluateNum{
    if (!_EvaluateNum) {
        _EvaluateNum = [[UILabel alloc]init];
        _EvaluateNum.textColor = kBDTimeColor;
        _EvaluateNum.textAlignment = NSTextAlignmentRight;
        _EvaluateNum.font = [UIFont systemFontOfSize:13];
    }
    return _EvaluateNum;
}
-(UILabel *)locationLabel{
    if (!_locationLabel) {
        _locationLabel = [[UILabel alloc]init];
        _locationLabel.textColor = kBDTimeColor;
        _locationLabel.font = [UIFont systemFontOfSize:13];
    }
    return _locationLabel;
}
-(UILabel *)rangLabel{
    if (!_rangLabel) {
        _rangLabel = [[UILabel alloc]init];
        _rangLabel.textColor = kBDTimeColor;
        _rangLabel.font = [UIFont systemFontOfSize:12];
        _rangLabel.textAlignment = NSTextAlignmentRight;
    }
    return _rangLabel;
}

-(UILabel *)yishouLabel{
    if (!_yishouLabel) {
        self.yishouLabel = [[UILabel alloc] init];
        _yishouLabel.textColor = kBDTimeColor;
        _yishouLabel.font = [UIFont systemFontOfSize:11];
        _yishouLabel.textAlignment = NSTextAlignmentRight;
    }
    return _yishouLabel;
}

-(void)addSubViews{
    [self addSubview:self.coverImage];
    [self addSubview:self.shopName];
    [self addSubview:self.starView];
    [self addSubview:self.EvaluateNum];
    [self addSubview:self.locationLabel];
    [self addSubview:self.rangLabel];
    [self addSubview:self.tuiguangLabel];
    [self addSubview:self.yishouLabel];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.coverImage.size = CGSizeMake(65, 65);
    self.coverImage.left = 5;
    self.coverImage.centerY = self.height / 2.0;
    
    [self.shopName sizeToFit];
    self.shopName.left = self.coverImage.right + 5;
    self.shopName.top = self.coverImage.top + 5;
    
    [self.yishouLabel sizeToFit];
    self.yishouLabel.right = self.width - 5;
    self.yishouLabel.centerY = self.shopName.centerY;
    
    CGFloat titleMaxWidth = self.yishouLabel.left - 10 - self.coverImage.right - (self.tuiguangLabel.hidden == YES ? 0 : 20) - (self.hongbaoImage.hidden == YES ? 0 : 20);
    self.shopName.width = MIN(titleMaxWidth, self.shopName.width);
    
    self.tuiguangLabel.centerY = self.shopName.centerY;
    self.tuiguangLabel.left = self.shopName.right + 5;
    
    self.hongbaoImage.size = CGSizeMake(18, 18);
    self.hongbaoImage.centerY = self.tuiguangLabel.centerY;
    self.hongbaoImage.left = (self.tuiguangLabel.hidden ? self.shopName.right : self.tuiguangLabel.right) + 5;
    
    self.locationLabel.size = CGSizeMake(self.width - self.coverImage.right - 10, self.locationLabel.font.pointSize+1);
    self.locationLabel.left = self.shopName.left;
    self.locationLabel.bottom = self.coverImage.bottom - 5;
    
    [self.rangLabel sizeToFit];
    self.rangLabel.right = self.width - 5;
    self.rangLabel.centerY = self.locationLabel.centerY;
    self.locationLabel.width = self.rangLabel.left - self.coverImage.right - 10;
    
    [self.starView setStarWidth:12 starSpace:1.2 andDelegate:nil];
    self.starView.isIndicator =YES;
    self.starView.bottom = self.locationLabel.top - 8;
    self.starView.left = self.shopName.left;
    
    self.EvaluateNum.size = CGSizeMake([self.EvaluateNum.text widthWithFont:self.EvaluateNum.font], self.EvaluateNum.font.pointSize+1);
    self.EvaluateNum.left = self.starView.right + 5;
    self.EvaluateNum.centerY =self.starView.centerY;
    
    self.backgroundColor = [UIColor whiteColor];
}

@end

